package com.ruoyi.bizsys.service.impl;

import java.util.List;
import java.util.Arrays;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.ruoyi.common.utils.DateUtils;
            import org.springframework.stereotype.Service;
    import com.ruoyi.bizsys.mapper.AccountFlowMapper;
import com.ruoyi.bizsys.domain.AccountFlow;
import com.ruoyi.bizsys.service.IAccountFlowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


/**
 * 账目流水Service业务层处理
 *
 * @author african-loan
 * @date 2022-05-06
 */
@Service
public class AccountFlowServiceImpl extends ServiceImpl<AccountFlowMapper,AccountFlow> implements IAccountFlowService {

    /**
     * 查询账目流水
     *
     * @param id 账目流水ID
     * @return 账目流水
     */
    @Override
    public AccountFlow selectAccountFlowById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询账目流水列表
     *
     * @param AccountFlow 账目流水
     * @return 账目流水
     */
    @Override
    public List<AccountFlow> selectAccountFlowList(AccountFlow AccountFlow) {
        return this.list(new QueryWrapper<>(AccountFlow).last("order by id desc"));
    }

    /**
     * 新增账目流水
     *
     * @param AccountFlow 账目流水
     * @return 结果
     */
            @Override
    public int insertAccountFlow(AccountFlow AccountFlow) {
                                                                                                                                                                                                                                                                                                                            AccountFlow.setCreateTime(DateUtils.getNowDate());
                                                                    return baseMapper.insert(AccountFlow);
    }

    /**
     * 修改账目流水
     *
     * @param AccountFlow 账目流水
     * @return 结果
     */
            @Override
    public int updateAccountFlow(AccountFlow AccountFlow) {
                                                                                                                                                                                                                                                                                                                                                                    AccountFlow.setUpdateTime(DateUtils.getNowDate());
                            return baseMapper.updateById(AccountFlow);
    }

    /**
     * 批量删除账目流水
     *
     * @param ids 需要删除的账目流水ID
     * @return 结果
     */
            @Override
    public int deleteAccountFlowByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除账目流水信息
     *
     * @param id 账目流水ID
     * @return 结果
     */
    @Override
    public int deleteAccountFlowById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public int insertByIndex(AccountFlow accountFlow) {
        //防止同一个对象插入问题，代码不规范
        accountFlow.setId(IdWorker.getId());
        return baseMapper.insertByIndex(accountFlow);
    }

}
